home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / bsnews / rnews.c < prev    next >
C/C++ Source or Header  |  1989-08-24  |  2KB  |  118 lines

  1. /*
  2.  * rnews.c - uux command for bootstrap news
  3.  * copyright 1989 Ronald Florence (ron@mlfarm 7/9/89)
  4.  *
  5.  * Modified (a lot) for use with MT C-Shell by David Beckemeyer
  6.  *  (david@bdt 8/23/89)
  7.  * 
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <time.h>
  12.  
  13. #define MAILER "\\usr\\bin\\rmail.prg"
  14. #define USER "netnews"
  15.  
  16. #ifndef Newsspool
  17. #define Newsspool    "\\usr\\spool\\news\\bsnews"
  18. #endif
  19. #ifndef Feeder
  20. #define Feeder         "Usenet"
  21. #endif
  22.  
  23. extern char **environ;
  24.  
  25. extern char *feedhost();
  26.  
  27. main()
  28. {
  29.   FILE    *nf, *cf;
  30.   char  buf[BUFSIZ];
  31.   register  c;
  32.   int    new = 1, n;
  33.  
  34.   while (fgets(buf, BUFSIZ, stdin) != NULL)
  35.     {
  36.                 /* batched? */
  37.       if (!strncmp(buf, "#! ", 3))
  38.     {
  39.                 /* compressed? */
  40.       if (!strncmp(buf+3, "cunbatch", 8))
  41.         {
  42.           fprintf(stderr, "cannot handle compressed batches yet\n");
  43.           exit(1);
  44.         }
  45.                 /* unpack the batch */
  46.       else if (sscanf(buf+3, "rnews %d", &n) == 1)  
  47.         {
  48.           if (!(nf = fopen(Newsspool, "w")))
  49.           {
  50.              fprintf(stderr, "rnews: can't write to %s\n", Newsspool);
  51.              exit(1);
  52.               }
  53.  
  54.           timestamp(nf);
  55.           for (c = 0; c < n; c += strlen(buf))
  56.         {
  57.           fgets(buf, BUFSIZ, stdin);
  58.           if (!strncmp(buf, "From ", 5))
  59.             putc('>', nf);
  60.           fputs(buf, nf);
  61.         }
  62.           putc('\n', nf);
  63.           fclose(nf);
  64.           sendmail();
  65.           continue;
  66.         }
  67.     }
  68.                 /* it must be unbatched */
  69.       else    
  70.     {
  71.       if (new)
  72.         {
  73.           if (!(nf = fopen(Newsspool, "w")))
  74.           {
  75.              fprintf(stderr, "rnews: can't write to %s\n", Newsspool);
  76.              exit(1);
  77.               }
  78.           timestamp(nf);
  79.           new = 0;
  80.         }
  81.       if (!strncmp(buf, "From ", 5))
  82.         putc('>', nf);
  83.       fputs(buf, nf);
  84.     }
  85.     }
  86.   if (!new) {
  87.     putc('\n', nf);
  88.     fclose(nf);
  89.     sendmail();
  90.   }
  91.   exit(0);
  92. }
  93.  
  94. static char *mailargv[] = {
  95.     "rmail",
  96.     Newsspool,
  97.     USER,
  98.     0
  99. };
  100.  
  101. sendmail()
  102. {
  103.     execve(MAILER, mailargv, environ);
  104. }
  105.  
  106. timestamp(newsfile)
  107. FILE  *newsfile;
  108. {
  109.   long    clock;
  110.   char    *ctime();
  111.   char *p, cb[32];
  112.  
  113.   time(&clock);
  114.   strcpy(cb, ctime(&clock));
  115.   cb[strlen(cb)-1] = 0;
  116.   fprintf(newsfile, "From %s %s remote from %s\n\n", Feeder, cb, feedhost());
  117. }
  118.